package com.ed.controller;

import com.ed.domain.ResponseDetails;
import com.ed.dto.PageAnalysisDto;
import com.ed.dto.PageQueryDto;
import com.ed.mapper.IResponseDetailsMapper;
import com.ed.result.PageResult;
import com.ed.result.Result;
import com.ed.service.QuestionAnalysisService;
import com.ed.vo.QuestionAnalysisVO;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 问答数据总览
 */
@RestController
@Slf4j
@CrossOrigin
@RequiredArgsConstructor
@RequestMapping("/QuestionAnalysis")
public class QuestionAnalysisController {
    @Autowired
    private QuestionAnalysisService questionAnalysisService;

    /**
     * 问答数据总览
     * @return
     */
    @GetMapping("/listData")
    public Result<QuestionAnalysisVO> listData() {
        QuestionAnalysisVO questionAnalysisVO = questionAnalysisService.listData();
        return Result.success(questionAnalysisVO);
    }

    /**
     * 分页查询问答数据
     * @param pageAnalysisDto
     * @return
     */
    @GetMapping("/PageQuery")
    public Result<PageResult> PageQuery(PageAnalysisDto pageAnalysisDto) {
        int pageNo = pageAnalysisDto.getPageNo();
        int pageSize = pageAnalysisDto.getPageSize();
        pageAnalysisDto.setPageSize((pageNo - 1) * pageSize);
        pageAnalysisDto.setPageNo(pageSize);
        PageResult pageResult = questionAnalysisService.PageQuery(pageAnalysisDto);
        return Result.success(pageResult);
    }


    /**
     * 查询答题详情
     * @param id
     * @return
     */
    @GetMapping("/details")
    public Result<List<ResponseDetails>> details(@RequestParam Integer id) {
        List<ResponseDetails> res =  questionAnalysisService.selectDetailsById(id);
        return Result.success(res);
    }
}
